<?php
	class BaseAction extends Action{
		function _initialize(){
// 			header("Content-Type:text/html; charset=utf-8");
			if(!isset($_SESSION[C('USER_AUTH_KEY')])){
				$this->assign("jumpUrl","__APP__/Public/login");
				$this->error('请先登陆！');
			}
			
			//对各个模块统一检查权限
			$actionName = null == $this->getActionName() ? 'Index' : $this->getActionName();
			$actionId = $this->getActionId(ucfirst($actionName));
			if(isset($_SESSION['permission'])){
				
				if('Index' == $actionName || 'Public' == $actionName){//Index跟Public模块不验证
				}else if(!in_array($actionId,explode(',', $_SESSION['permission']))){
					$this->error('权限不足，无法管理该模块！');
					exit();
				}
			}else{
				$this->assign("jumpUrl","__APP__/Public/login");
				$this->error('请重新登陆！');
			}
		}
		
		//返回各模块权限标记
		private function getActionId($actionName){
			switch ($actionName){
				case 'Public':
					return 1;
				case 'Manager':
					return 3;
				case 'Level':
					return 4;
				case 'Permission':
					return 5;
				case 'Category':
					return 6;
				case 'Article':
					return 7;
				case 'Comment':
					return 8;
				case 'Rotation':
					return 9;
				case 'Adver':
					return 10;
				case 'Vote':
					return 11;
				case 'Link':
					return 12;
				case 'User':
					return 13;
				case 'System':
					return 14;
				default:
					return ;
			}
		}
	}
?>